package com.niit.activity.mapper;

import org.apache.ibatis.annotations.*;

@Mapper
public interface LikeMapper {

    @Insert("INSERT INTO user_activity_like (user_id, activity_id, like_status) VALUES (#{userId}, #{activityId}, 1)")
    int insertLike(@Param("userId") Long userId, @Param("activityId") Long activityId);

    @Update("UPDATE user_activity_like SET like_status = #{status} WHERE user_id = #{userId} AND activity_id = #{activityId}")
    int updateLikeStatus(@Param("userId") Long userId, @Param("activityId") Long activityId, @Param("status") int status);

    @Select("SELECT like_status FROM user_activity_like WHERE user_id = #{userId} AND activity_id = #{activityId}")
    Integer getLikeStatus(@Param("userId") Long userId, @Param("activityId") Long activityId);

    @Select("SELECT COUNT(*) FROM user_activity_like WHERE activity_id = #{activityId} AND like_status = 1")
    int countLikesByActivityId(@Param("activityId") Long activityId);
}

